package cn.yr.controller.manage;


import cn.yr.common.util.AjaxResult;
import cn.yr.domain.entity.Article;
import cn.yr.domain.page.TableDataInfo;
import cn.yr.domain.vo.ArticleVo;
import cn.yr.service.manage.ISysArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文章Controller
 *
 * @author ruoyi
 * @date 2020-03-21
 */
@RestController
@RequestMapping("/system/article")
public class SysArticleController extends BaseController {
	@Resource
	private ISysArticleService sysArticleService;

	/**
	 * 查询文章列表
	 */
	@GetMapping("/list")
	public TableDataInfo list(Article article) {
		startPage();
		List<Article> list = sysArticleService.selectArticleList(article);
		return getDataTable(list);
	}


	/**
	 * 获取文章详细信息
	 */
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(sysArticleService.selectArticleById(id));
	}

	@PostMapping("save")
	public  AjaxResult save(@RequestBody ArticleVo articleVo){
		return toAjax(sysArticleService.insertArticle(articleVo));
	}

	/**
	 * 新增文章
	 */
	@PostMapping
	public AjaxResult add(@RequestBody Article article) {
		return toAjax(sysArticleService.insertArticle(article));
	}

	/**
	 * 修改文章
	 */
	@PutMapping
	public AjaxResult edit(@RequestBody Article article) {
		return toAjax(sysArticleService.updateArticle(article));
	}

	/**
	 * 删除文章
	 */
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(sysArticleService.deleteArticleByIds(ids));
	}
}
